package com.wct.permission.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

/**
 * @author WEI (Email:changtan20000@163.com)
 * @description
 * @date 2020/2/14 23:33
 */

@EnableWebMvc
@ControllerAdvice
@Slf4j
public class HandleControllerAdvice {

    @ExceptionHandler(RuntimeException.class)
    public String exceptionHandler(RuntimeException e) {
        if(e != null) {
            log.error("{}", e.getMessage());
        }
        if (e instanceof AccessDeniedException) {
            //如果是权限不足异常，则跳转到权限不足页面！
            return "redirect:/403.jsp";
        }
        //其余的异常都到500页面！
        return "redirect:/500.jsp";
    }
}
